<?php
	include_once('../config.php');
	LinkDataBase();
	
	?>
	<script type="text/javascript">
	var year = <?php echo $_POST['year']; ?>;
	var season = '<?php echo $_POST['season']; ?>';
	var div;
	var url;
    <?php
	$index = 0;
	
	//Find sheet in droplist.
	$sql = "SELECT * FROM droplist, sheetreveal_first 
			WHERE droplist.id = droplist_id AND droplist.year = ".$_POST['year']." AND droplist.season = '".$_POST['season']."' 
			AND droplist.name = '".$_POST['type']."' AND location_index NOT LIKE 999
			ORDER BY location_index";
	$result= mysql_query($sql);
	
	while($row = mysql_fetch_assoc($result)) {
		
		$table = $row['table_number'];
		$charttype = $row['charttype'];
		$index++;
		
		$Array_Title[] = $row['charttitle'];
	?>
		div = 'chart-<?php echo $index; ?>';
		href = 'href-<?php echo $index; ?>';
				
		ChartType = '#<?php echo $charttype; ?>';
				
		//Process keyword.
		var keyword = '';
		<?php
		if (isset($row['keyword'])) {
		?>
			keyword = '<?php echo $row['keyword']; ?>';
		<?php
		}
		?>
					
		//Process contain.
		var contain = '';
		<?php
		if (isset($row['contain'])) {
		?>
			contain = '<?php echo $row['contain']; ?>';
		<?php
		}
		?>
		
		$("#"+div+"").load('../chart/<?php echo $charttype; ?>Chart.php',
		{'year':year, 'season':season, 'tablename': '<?php echo $table; ?>', 'keyword': keyword, 
		'contain': contain});
		
		//Change href.
		$('#content-chart td#'+href+' a').attr('href','#<?php echo $table; ?>'+ChartType+'#'+keyword+'#'+contain);
		<?php
	}
	
	//Process odd number.
	if ($index%2==1) {
		if ($index>6)
			$index = 6;
		else
			$index = $index-1;
	}
	?>
			
	function GotoDetail(href, title) {
					
		var year = $("#year-droplist").text();
		var season = $("#season-droplist").text();
		var type = $("#type-droplist").text();
		var Array_Href = $(href).attr('href').split('#');
		$("#content-detail").load('../chart/detail/index.php',
		{'year':year, 'season':season, 'type':type, 'tablename': Array_Href[1], 'charttype': Array_Href[2], 
		'keyword': Array_Href[3], 'contain': Array_Href[4], 
		'previous_title': '<a href="#" onclick="GotoBegin();" >'+title+'</a>', 'step': 1});
		
		console.log(Array_Href);
	}
	</script>  
<div class="container2" id="content-chart">
	<div>
	<?php
	if ($index==6) {
	?>
    <table>
    <tr>
    <td>
  	  <table width="300" border="1" cellspacing="0" cellpadding="0" class="tablegenericleft" style="margin-left: 30px">
  	    <tr>
  	      <td align="center" bgcolor="#f9f9f9" color="#909090" height="40px" class="tabletop" id="href-1"><?php echo $Array_Title[0]; ?><a href="#" onclick="GotoDetail(this,'<?php echo $Array_Title[0]; ?>');"><img src="../images/right-arrow.png" width="7" height="12" align="right" style="position:relative; top:3px; left:-10px; font-size:14pt; font-family:Helvetica, Arial, sans-serif"></a>
          </td>
        </tr>
  	    <tr>
  	      <td align="center" class="tableimg">
          	<div id="chart-1"></div>
          </td>
        </tr>
      </table>
    </td>
    <td>
      <table width="300" border="1" cellspacing="0" cellpadding="0" class="tablegeneric" style="padding: 0 20px 0 20px">
  	    <tr>
  	      <td align="center" bgcolor="#f9f9f9" color="#909090" height="40px" class="tabletop" id="href-2"><?php echo $Array_Title[1]; ?><a href="#" onclick="GotoDetail(this,'<?php echo $Array_Title[1]; ?>');"><img src="../images/right-arrow.png" width="7" height="12" align="right" style="position:relative; top:3px; left:-10px; font-size:14pt; font-family:Helvetica, Arial, sans-serif"></a></td>
	   	</tr>
  	    <tr>
  	      <td align="center" class="tableimg">
          	<div id="chart-2"></div>
          </td>
	    </tr>
	  </table>
    </td>
    <td>
      <table width="300" border="1" cellspacing="0" cellpadding="0" class="tablegeneric" style="padding: 0 20px 0 20px">
  	   	<tr>
  	      <td align="center" bgcolor="#f9f9f9" color="#909090" height="40px" class="tabletop" id="href-3"><?php echo $Array_Title[2]; ?><a href="#" onclick="GotoDetail(this,'<?php echo $Array_Title[2]; ?>');"><img src="../images/right-arrow.png" width="7" height="12" align="right" style="position:relative; top:3px; left:-10px; font-size:14pt; font-family:Helvetica, Arial, sans-serif"></a>
          </td>
	    </tr>
  	   	<tr>
  	      <td align="center" class="tableimg">
          	<div id="chart-3"></div>
          </td>
	    </tr>
	  </table>
   	</td>
   </tr>
   
   <tr>
   	<td>
      <table width="300" border="1" cellspacing="0" cellpadding="0" class="tablegenericleft" style="padding: 0 20px 0 20px">
  	   	<tr>
  	      <td align="center" bgcolor="#f9f9f9" color="#909090" height="40px" class="tabletop" id="href-4"><?php echo $Array_Title[3]; ?><a href="#" onclick="GotoDetail(this,'<?php echo $Array_Title[3]; ?>');"><img src="../images/right-arrow.png" width="7" height="12" align="right" style="position:relative; top:3px; left:-10px; font-size:14pt; font-family:Helvetica, Arial, sans-serif"></a>
          </td>
	    </tr>
  	    <tr>
  	      <td align="center" class="tableimg">
          	<div id="chart-4"></div>
          </td>
	    </tr>
	 </table>
   </td>
   <td>
	 <table width="300" border="1" cellspacing="0" cellpadding="0" class="tablegeneric" style="padding: 0 20px 0 20px">
  	    <tr>
  	     <td align="center" bgcolor="#f9f9f9" color="#909090" height="40px" class="tabletop" id="href-5"><?php echo $Array_Title[4]; ?><a href="#" onclick="GotoDetail(this,'<?php echo $Array_Title[4]; ?>');"><img src="../images/right-arrow.png" width="7" height="12" align="right" style="position:relative; top:3px; left:-10px; font-size:14pt; font-family:Helvetica, Arial, sans-serif"></a>
         </td>
	    </tr>
  	    <tr>
  	      <td align="center" class="tableimg">
          	<div id="chart-5"></div>
          </td>
	    </tr>
	 </table>
   </td>
   <td>
     <table width="300" border="1" cellspacing="0" cellpadding="0" class="tablegeneric" style="padding: 0 20px 0 20px">
  	    <tr>
  	      <td align="center" bgcolor="#f9f9f9" color="#909090" height="40px" class="tabletop" id="href-6"><?php echo $Array_Title[5]; ?><a href="#" onclick="GotoDetail(this,'<?php echo $Array_Title[5]; ?>');"><img src="../images/right-arrow.png" width="7" height="12" align="right" style="position:relative; top:3px; left:-10px; font-size:14pt; font-family:Helvetica, Arial, sans-serif"></a>
          </td>
	    </tr>
  	    <tr>
  	      <td align="center" class="tableimg">
          	<div id="chart-6"></div>
          </td>
	    </tr>
	 </table>
   </td>
  </tr>
 </table>
	<?php
	}
	else if ($index==4) {
	?>
    <table>
    <tr>
    <td>
  	  <table width="300" border="1" cellspacing="0" cellpadding="0" class="tablegenericleft" style="margin-left: 200px">
  	    <tr>
  	      <td align="center" bgcolor="#f9f9f9" color="#909090" height="40px" class="tabletop" id="href-1"><?php echo $Array_Title[0]; ?><a href="#" onclick="GotoDetail(this,'<?php echo $Array_Title[0]; ?>');"><img src="../images/right-arrow.png" width="7" height="12" align="right" style="position:relative; top:3px; left:-10px; font-size:14pt; font-family:Helvetica, Arial, sans-serif"></a>
          </td>
        </tr>
  	    <tr>
  	      <td align="center" class="tableimg">
          	<div id="chart-1"></div>
          </td>
        </tr>
      </table>
    </td>
    <td>
      <table width="300" border="1" cellspacing="0" cellpadding="0" class="tablegeneric" style="padding: 0 20px 0 20px">
  	    <tr>
  	      <td align="center" bgcolor="#f9f9f9" color="#909090" height="40px" class="tabletop" id="href-2"><?php echo $Array_Title[1]; ?><a href="#" onclick="GotoDetail(this,'<?php echo $Array_Title[1]; ?>');"><img src="../images/right-arrow.png" width="7" height="12" align="right" style="position:relative; top:3px; left:-10px; font-size:14pt; font-family:Helvetica, Arial, sans-serif"></a></td>
	   	</tr>
  	    <tr>
  	      <td align="center" class="tableimg">
          	<div id="chart-2"></div>
          </td>
	    </tr>
	  </table>
    </td>
   </tr>
   <tr>
   	<td>
      <table width="300" border="1" cellspacing="0" cellpadding="0" class="tablegenericleft" style="margin-left: 200px">
  	   	<tr>
  	      <td align="center" bgcolor="#f9f9f9" color="#909090" height="40px" class="tabletop" id="href-3"><?php echo $Array_Title[2]; ?><a href="#" onclick="GotoDetail(this,'<?php echo $Array_Title[2]; ?>');"><img src="../images/right-arrow.png" width="7" height="12" align="right" style="position:relative; top:3px; left:-10px; font-size:14pt; font-family:Helvetica, Arial, sans-serif"></a>
          </td>
	    </tr>
  	    <tr>
  	      <td align="center" class="tableimg">
          	<div id="chart-3"></div>
          </td>
	    </tr>
	 </table>
   </td>
   <td>
	 <table width="300" border="1" cellspacing="0" cellpadding="0" class="tablegeneric" style="padding: 0 20px 0 20px">
  	    <tr>
  	     <td align="center" bgcolor="#f9f9f9" color="#909090" height="40px" class="tabletop" id="href-4"><?php echo $Array_Title[3]; ?><a href="#" onclick="GotoDetail(this,'<?php echo $Array_Title[3]; ?>');"><img src="../images/right-arrow.png" width="7" height="12" align="right" style="position:relative; top:3px; left:-10px; font-size:14pt; font-family:Helvetica, Arial, sans-serif"></a>
         </td>
	    </tr>
  	    <tr>
  	      <td align="center" class="tableimg">
          	<div id="chart-4"></div>
          </td>
	    </tr>
	 </table>
   </td>
  </tr>
 </table>
   <?php 
	}
	else if ($index==2) {
   ?>
   <table>
    <tr>
    <td>
  	  <table width="300" border="1" cellspacing="0" cellpadding="0" class="tablegenericleft" style="margin-left: 200px">
  	    <tr>
  	      <td align="center" bgcolor="#f9f9f9" color="#909090" height="40px" class="tabletop" id="href-1"><?php echo $Array_Title[0]; ?><a href="#" onclick="GotoDetail(this,'<?php echo $Array_Title[0]; ?>');"><img src="../images/right-arrow.png" width="7" height="12" align="right" style="position:relative; top:3px; left:-10px; font-size:14pt; font-family:Helvetica, Arial, sans-serif"></a>
          </td>
        </tr>
  	    <tr>
  	      <td align="center" class="tableimg">
          	<div id="chart-1"></div>
          </td>
        </tr>
      </table>
    </td>
    <td>
      <table width="300" border="1" cellspacing="0" cellpadding="0" class="tablegeneric" style="padding: 0 20px 0 20px">
  	    <tr>
  	      <td align="center" bgcolor="#f9f9f9" color="#909090" height="40px" class="tabletop" id="href-2"><?php echo $Array_Title[1]; ?><a href="#" onclick="GotoDetail(this,'<?php echo $Array_Title[1]; ?>');"><img src="../images/right-arrow.png" width="7" height="12" align="right" style="position:relative; top:3px; left:-10px; font-size:14pt; font-family:Helvetica, Arial, sans-serif"></a></td>
	   	</tr>
  	    <tr>
  	      <td align="center" class="tableimg">
          	<div id="chart-2"></div>
          </td>
	    </tr>
	  </table>
    </td>
   </tr>
   </table>
   <?php
   }
   ?>
</div>
</div>